package com.oauth.oauth.util;

import com.alibaba.fastjson.JSONObject;

import java.io.Serializable;
import java.util.Map;

public class R extends JSONObject implements Serializable {
    private static final long serialVersionUID = 1024L;
    private static final String PROPERTY_SUCCESS = "success";
    private static final String PROPERTY_MESSAGE = "msg";
    private static final String PROPERTY_ERRORDESC = "desc";
    private static final String PROPERTY_TOTAL = "total";
    private static final String PROPERTY_ROWS = "rows";
    private static final String PROPERTY_DATA = "data";

    public R() {
        this.put((String)"success", true);
        this.put((String)"msg", "");
    }

    public static R success(String msg) {
        R r = new R();
        r.put((String)"msg", msg);
        return r;
    }

    public static R success() {
        return new R();
    }

    public static R success(Object value) {
        R r = new R();
        r.put("data", value);
        return r;
    }

    public static R error(String msg) {
        R r = new R();
        r.put((String)"success", false);
        r.put((String)"msg", msg);
        return r;
    }

    public static R error(String msg, String errCode) {
        R r = new R();
        r.put((String)"success", false);
        r.put((String)"msg", msg);
        r.put((String)"errCode", errCode);
        return r;
    }

    public R desc(String desc) {
        super.put("desc", desc);
        return this;
    }

    public R total(int total) {
        super.put("total", total);
        return this;
    }

    public R rows(Object value) {
        super.put("rows", value);
        return this;
    }

    public R page(long total, Object value) {
        super.put("rows", value);
        super.put("total", total);
        return this;
    }

    public R data(Object value) {
        super.put("data", value);
        return this;
    }

    public R errCode(String value) {
        super.put("errCode", value);
        return this;
    }

    public R put(String key, Object value) {
        super.put(key, value);
        return this;
    }

    public R fluentPutAll(Map<? extends String, ? extends Object> m) {
        super.fluentPutAll(m);
        return this;
    }

    public boolean ckSuccess() {
        return this.getBoolean("success");
    }
}
